package cn.com.idmy.auth.oauth;

import cn.com.idmy.base.IEnum;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.NotNull;

@Getter
@Accessors(fluent = true)
@RequiredArgsConstructor
public enum GrantType implements IEnum<String> {
    AUTHORIZATION_CODE("authorization_code", "授权码"),
    IMPLICIT("token", "隐藏式"),
    REFRESH_TOKEN("refresh_token", "更新令牌"),
    PASSWORD("password", "密码式"),
    CLIENT_CREDENTIALS("client_credentials", "客户端模式");

    private final String value;
    private final String title;

    public static @NotNull GrantType of(String grantType) {
        for (GrantType type : GrantType.values()) {
            if (type.value.equals(grantType)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效 grant_type: " + grantType);
    }
}
